﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Liber;
using Liber.WEB;

namespace SoBusiness.Controllers
{
    public class CloudAdminController :LiberController
    {
        // GET: CloudAdmin
        public ActionResult Index()
        {
            return View();
        }

        public ViewResult AcntApprove()
        {
            return View();
        }

        public ViewResult CompanyApprove()
        {
            return View();
        }
        public ViewResult PendingCompanyApprove()
        {
            return View();
        }
        public ViewResult PendingAcntApprove()
        {
            return View();
        }

        public JsonResult GetPendingAcnt()
        {
            return Json(API.Request("AccountSvc@GetPendingCertification")
                           .WaitResult());
        }

        public JsonResult ApproveAcnt(long idstr, string result,string feedback)
        {
            //string socialid = Request.QueryString.TryGet("socialid");
            string socialid = Request.Form.Get("socialid");
            return Json(API.Request("AccountSvc@ApproveCertification")
                           .Set("certificationid", idstr)
                           .Set("result", result)
                           .Set("feedback", feedback)
                           .Set("socialid", socialid)
                           .WaitResult());
        }

        public JsonResult GetPendingCompany()
        {
            return Json(API.Request("OrganizeSvc@GetPendingCertification")
                           .WaitResult());
        }

        public JsonResult ApproveCompany(long idstr,string result,string feedback)
        {
            string name = Request.Form.Get("name");
            string bizorgcode = Request.Form.Get("bizorgcode");
            string licencecode = Request.Form.Get("licencecode");

            return Json(API.Request("OrganizeSvc@ApproveCertification")
                           .Set("certificationid", idstr)
                           .Set("result", result)
                           .Set("feedback", feedback)
                           .Set("name",name)
                           .Set("bizorgcode",bizorgcode)
                           .Set("licencecode", licencecode)
                           .WaitResult());
        }

        public JsonResult RegisterAuthority(string app,string bizobj,string bizaction)
        {
            return Json(API.Request("AuthoritySvc@RegisterAuthority")
                           .Set("app", app)
                           .Set("bizobj", bizobj)
                           .Set("bizaction", bizaction)
                           .WaitResult());
        }

        public JsonResult UpdateSetting()
        {
            XMLSetting.SetDefault(Server.MapPath("") + "\\NodeConfig.cfg");
            return Json(null);
        }

        public JsonResult RematchOrder(long acnt)
        {
            return Json(API.Request("PurchaseApp@RematchOrder")
                           .Set("acnt", acnt)
                           .WaitResult());
                
        }


        [NoSession]
        public void Debug()
        {
            Log(Request.QueryString.FastJson());
        }
    }
}